Page({
  data: {
    date: '',
    show: false,
    year: 21,
    Month: 6,
    newdate: "",
    money: "0",
    incomemoney: "0"
  },

  onDisplay(e) {
    this.setData({ show: true });
    console.log(e)
  },
  onClose(e) {
    this.setData({ show: false });
    console.log(e)

  },
  formatDate(date) {
    date = new Date(date);
    console.log(date)
    this.data.year = `${date.getFullYear()}`
    this.setData({
      year: `${date.getFullYear()}`,
      Month: `${date.getMonth() + 1}`
    })
    console.log(this.data.year)
    this.getnew()
    return `${date.getYear() - 100}/${date.getMonth() + 1}/${date.getDate()}`;

  },
  onConfirm(event) {
    this.setData({
      show: false,
      date: this.formatDate(event.detail),
    });
    console.log(this.formatDate(event.detail))
    this.setData({
      newdate: this.formatDate(event.detail)
    })

  },
  gettime() {
    this.setData({ show: true });
  },
  getnewtime() {
    var myDate = new Date();
    var fullyear = `${myDate.getFullYear()}/${myDate.getMonth() + 1}/${myDate.getDate()}`
    console.log(fullyear)
    this.setData({
      newdate: fullyear
    })
  },
  onShow() {
    this.getnewtime(),
      this.getnew()
  },
  getnew() {
    var expenditure = 0
    var income = 0
    var option = []
    var userId = getApp().globalData.userId
    console.log(this.data.year)
    var that = this
    wx.request({
      url: 'http://127.0.0.1:8181/bill/queryBillByMonth?year=2021&month=' + that.data.Month + '&userId=' + userId,
      success(res) {
        // console.log(res)
        // console.log(that.data.year)
        for (var i = 0; i < res.data.length; i++) {
          if (res.data[i].billType === '支出') {

            expenditure = res.data[i].money + expenditure
            // console.log(expenditure)
            that.data.money = expenditure
          } else {
            // console.log(res.data[i].money)
            income = res.data[i].money + income
            // console.log(income)
            that.data.incomemoney = income
          }
          res.data[i].billDate = res.data[i].billDate.split("T")[0]
        }
        // console.log(expenditure)
        // console.log(that.data.money)
        that.setData({
          expenditure: that.data.money,
          option: res.data,
          incomemoney: that.data.incomemoney

        })


      }
    })
  },
  today_deleteBill(e) {
    console.log(e.currentTarget.dataset.details)
    wx.navigateTo({
      url: '/pages/details/details?details=' + JSON.stringify(e.currentTarget.dataset.details),
    })
  }
});